<?php

/**
* Controller:  "Secure"
*
* This controller allows for more functionality than any controller.  From
* this page, logged-in users can add or remove a pet, or add and remove an
* event from the database.  Changes made here are reflected instantly.
* Deletions allow the users to delete one, then redirect to a page to delete
* another.  Additions redirect back to this page, which also allows more pets
* or events to be added.
*
* Functions:  index
*
* @author     Brandon A Johnson
* @copyright  LIS4368-01: "Web Development with PHP," Spring 2010
* @version    1.0
* @date       April 24, 2010
*
*/

class Secure extends Controller {
	
	/**
	* Secure() - constructor
	*
	* allows this file to act as a valid CodeIgniter controller
	*/
	function Secure()
	{
		parent::Controller();
	}

	/**
	* index()
	*
	* This page allows the user to perform one of four operations:
	*
	*    -- remove a pet record from the database
	*    -- add a new pet record to the database
	*    -- remove an event record from the database
	*    -- add a new event record to the database
	*
	* Each operation must be performed by itself - in other words,
	* only one operation at a time.  The deletion functions will
	* redirect to new apges, while the addition functions will
	* point back to this page and print a success/failure message.
	*/
	function index()
	{
		// load the session library
		$this->load->library('session');
		
		// make sure the user is logged in
		if ($this->session->userdata('is_logged_in'))
		{
			// loads the "pets" database interaction model
			$this->load->model('pets_model');
			// extracts all pet records currently in the table
			$all_pets = $this->pets_model->list_pets();
			// prepares the data to be sent to the view
			$data = array();
			$data['results'] = $all_pets;
			
			// loads the "events" database interaction model
			$this->load->model('events_model');
			// extracts all event records currently in the table
			$all_events = $this->events_model->list_events();
			// prepares the data to be sent to the view
			$data['events'] = $all_events;

			// loads the views
			$this->load->view('header');
			$this->load->view('secure', $data);
		}
		// otherwise...
		else
		{
			echo "You are not logged in!";
			
			$this->load->view('header');
			$this->load->view('login');
		}
	}
}

/* End of file secure.php */
/* Location: ./system/application/controllers/secure.php */